import 'package:flutter/material.dart';
import 'package:get/get_state_manager/src/simple/get_state.dart';

import '../../pages/main/main_logic.dart';

class FStyles {
  static const Color primaryColor = Color(0xFF165DFF);
  static const double btnHeight = 46;
  static const double? btnRadius = null;
  static const double btnFontSize = 16;
  static const TextStyle btnTextStyle = TextStyle(
      fontSize: 16,
      height: 1,
      fontWeight: FontWeight.w600,
      color: Colors.white);
  static const List<Color> gradientColors = [
    Color(0xFF2071BA),
    Color(0xFF1F2CFB),
    Color(0xFF3589F4)
  ];

  static BoxDecoration bgColor(
      {Color color = primaryColor, double? radius = btnRadius}) {
    return BoxDecoration(
        color: color,
        borderRadius: radius == null ? null : BorderRadius.circular(radius));
  }

  static BoxDecoration bgHGradient(
      {List<Color> colors = gradientColors,
      List<double>? stops,
      double? radius = btnRadius}) {
    return BoxDecoration(
        gradient: hLinearGradient(colors, stops: stops),
        borderRadius: radius == null ? null : BorderRadius.circular(radius));
  }

  static BoxDecoration bgVGradient(
      {List<Color> colors = gradientColors,
      List<double>? stops,
      double? radius = btnRadius}) {
    return BoxDecoration(
        gradient: vLinearGradient(colors, stops: stops),
        borderRadius: radius == null ? null : BorderRadius.circular(radius));
  }

  static BoxDecoration bgBorder(
      {Color color = primaryColor,
      double width = 1,
      double? radius = btnRadius}) {
    return BoxDecoration(
        border: Border.all(width: width, color: color),
        borderRadius: radius == null ? null : BorderRadius.circular(radius));
  }

  static BoxDecoration bgImage(String image, {double? radius = btnRadius}) {
    return BoxDecoration(
        borderRadius: radius == null ? null : BorderRadius.circular(radius),
        image: DecorationImage(image: AssetImage(image), fit: BoxFit.fill));
  }

  static LinearGradient hLinearGradient(List<Color> colors,
          {List<double>? stops}) =>
      LinearGradient(
          colors: colors,
          begin: Alignment.centerLeft,
          end: Alignment.centerRight,
          stops: stops);

  static LinearGradient vLinearGradient(List<Color> colors,
          {List<double>? stops}) =>
      LinearGradient(
          colors: colors,
          begin: Alignment.topCenter,
          end: Alignment.bottomCenter,
          stops: stops);

  static Widget btnText(String text,
      {TextStyle? style,
      double? fontSize,
      Color? color,
      FontWeight? fontWeight}) {
    final TextStyle textStyle = style ??
        btnTextStyle.copyWith(
            fontSize: fontSize ?? btnFontSize,
            color: color ?? btnTextStyle.color,
            fontWeight: fontWeight ?? btnTextStyle.fontWeight);
    return Text(text, style: textStyle);
  }

  static Widget btnIconText(
      {required Widget icon,
      required String text,
      TextStyle? style,
      double? fontSize,
      Color? color,
      FontWeight? fontWeight,
      double space = 8,
      TextDirection textDirection = TextDirection.ltr}) {
    final TextStyle textStyle = style ??
        btnTextStyle.copyWith(
            fontSize: fontSize ?? btnFontSize,
            color: color ?? btnTextStyle.color,
            fontWeight: fontWeight ?? btnTextStyle.fontWeight);
    return _iconText(icon, text, textStyle, space, textDirection);
  }

  static Widget btnImageText(
      {required String imageName,
      required String text,
      TextStyle? style,
      double? fontSize,
      Color? color,
      FontWeight? fontWeight,
      double? iconSize,
      Color? iconColor,
      double space = 8,
      TextDirection textDirection = TextDirection.ltr}) {
    final TextStyle textStyle = style ??
        btnTextStyle.copyWith(
            fontSize: fontSize ?? btnFontSize,
            color: color ?? btnTextStyle.color,
            fontWeight: fontWeight ?? btnTextStyle.fontWeight);
    Widget icon = Image.asset(imageName,
        width: iconSize ?? textStyle.fontSize ?? FStyles.btnFontSize,
        color: iconColor);
    return _iconText(icon, text, textStyle, space, textDirection);
  }

  static Widget btnPlayIconText(
      {required String playIcon,
      required String text,
      TextStyle? style,
      double? fontSize,
      Color? color,
      FontWeight? fontWeight,
      double? iconSize,
      Color? iconColor,
      double space = 8,
      TextDirection textDirection = TextDirection.ltr}) {
    final TextStyle textStyle = style ??
        btnTextStyle.copyWith(
            fontSize: fontSize ?? btnFontSize,
            color: color ?? btnTextStyle.color,
            fontWeight: fontWeight ?? btnTextStyle.fontWeight);
    Widget icon = FPlayIconWidget(
        margin: textDirection == TextDirection.ltr
            ? EdgeInsets.only(right: space)
            : EdgeInsets.only(left: space),
        imageName: playIcon,
        width: iconSize ?? textStyle.fontSize ?? FStyles.btnFontSize,
        color: iconColor);
    return _iconText(icon, text, textStyle, 0, textDirection);
  }

  static Widget _iconText(Widget icon, String text, TextStyle style,
      double space, TextDirection textDirection) {
    return Row(
      mainAxisSize: MainAxisSize.min,
      textDirection: textDirection,
      children: [
        icon,
        SizedBox(width: space),
        Text(text,
            style: style,
            strutStyle: const StrutStyle(
              height: 1.0,
              //leading: 0,
            ))
      ],
    );
  }
}

class FPlayIconWidget extends StatelessWidget {
  const FPlayIconWidget({
    super.key,
    required this.imageName,
    this.margin = EdgeInsets.zero,
    this.width = 16,
    this.color,
  });

  final EdgeInsets margin;
  final double width;
  final String imageName;
  final Color? color;

  @override
  Widget build(BuildContext context) {
    // return GetBuilder<VCMainLogic>(
    //   builder: (logic) {
    //     return Visibility(visible: logic.isShowPlayIcon, child: Padding(padding: margin, child: Image.asset(imageName, width: width, color: color)));
    //   },
    //   id: idShowPlayIcon,
    // );
    return GetBuilder<MainLogic>(
      builder: (logic) {
        return Visibility(
            visible: false,
            child: Padding(
                padding: margin,
                child: Image.asset(imageName, width: width, color: color)));
      },
      id: false,
    );
  }
}
